package com.example.demo.login;

import catcode.CatCodeUtil;
import com.example.demo.Service.BlacklistService;
import com.example.demo.Switch.PublicApiController;
import com.example.demo.mapper.AdminlengMapper;
import love.forte.common.ioc.annotation.Beans;
import love.forte.simbot.annotation.Filter;
import love.forte.simbot.annotation.OnGroup;
import love.forte.simbot.annotation.OnPrivate;
import love.forte.simbot.api.message.events.GroupMsg;
import love.forte.simbot.api.message.events.PrivateMsg;
import love.forte.simbot.api.sender.Sender;
import love.forte.simbot.filter.MatchType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Beans
public class PrivateTake {

    @Autowired
    private BlacklistService test;

    @Autowired
    private AdminlengMapper adminlengMapper;

    @Autowired
    private PublicApiController publicApiController;



    @OnPrivate
    @Filter( value ="^((?!#).)*$",matchType = MatchType.REGEX_FIND)
    public void groupalltake(PrivateMsg msg, Sender sender)
    {
        if(test.selectrole(msg.getAccountInfo().getAccountCode()))
        {
            List<String> groupid= adminlengMapper.selectgioupid();

            for (String id:groupid) {
                try {
                    sender.sendGroupMsg(id,msg.getMsgContent());
                }catch (Exception ignored)
                {
                }
            }
        }else
        {
            sender.sendPrivateMsg(msg.getAccountInfo().getAccountCode(), adminlengMapper.adminset(msg.getMsg()));
        }


       /* sender.sendPrivateMsg(msg.getAccountInfo().getAccountCode(), adminlengMapper.adminset(msg.getMsg()));*/
    }

    @OnPrivate
    @Filter(value = "#", matchType = MatchType.STARTS_WITH)
    public void API(PrivateMsg msg, Sender sender) {

        // 获取猫猫码工具
        CatCodeUtil util = CatCodeUtil.INSTANCE;
        // 构建image, 第二个参数为true代表参数值需要进行转义
        String image = util.toCat("image", true, "url=http://p2.qhimg.com/bdm/1280_800_85/t01847931bf22285e8c.jpg");
        sender.sendPrivateMsg(msg.getAccountInfo().getAccountCode(),image);
    }
}
